package cn.tworice.client.web;

import cn.tworice.client.service.ItemBankService;
import cn.tworice.common.entity.ItemBank;
import cn.tworice.common.entity.dto.ItemBankDto;
import com.lmk.core.web.support.api.RequestResult;
import com.lmk.core.web.support.api.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 题库管理控制层
 * @Author 二饭
 * @Email 1786705138@qq.com
 * @Date 2021/12/24 13:30
 */
@RestController
@RequestMapping("/client/itemBank")
@CrossOrigin
public class ItemBankClient {

    @Autowired
    private ItemBankService itemBankService;

    @GetMapping("")
    public RequestResult list(Integer page,Integer pageSize){
        RequestResult result = new RequestResult();
        List<ItemBankDto> list = itemBankService.getList(page,pageSize);
        Integer total=itemBankService.getTotal();
        result.appendData("list", list);
        result.appendData("total",total);
        return result;
    }

    @PutMapping("")
    public RequestResult set(ItemBank itemBank){
        RequestResult result = new RequestResult();
        itemBankService.set(itemBank);
        return result;
    }

    @DeleteMapping("")
    public RequestResult del(String[] id){
        RequestResult result = new RequestResult();
        Integer i = itemBankService.del(id);
        result.setCode(new StatusCode(200,"删除"+i+"条信息"));
        return result;
    }
}
